/**
 * @param {number[]} customers
 * @param {number[]} grumpy
 * @param {number} X
 * @return {number}
 */
var maxSatisfied = function (customers, grumpy, X) {
    let dic = new Map()
    let totalDic = new Map()
    let tmp = 0
    let totalTmp = 0
    for (let i = 0; i < customers.length; i++) {
        if (grumpy[i] == 0) {
            tmp += customers[i]
        }
        dic[i] = tmp
        totalTmp += customers[i]
        totalDic[i] = totalTmp
    }
    console.log(dic)
    console.log(totalDic)
    let res = 0
    let value = 0
    for (let i = 0; i <= customers.length - X; i++) {
        if (i != 0 && i != customers.length - X) {
            value = dic[i] - dic[0] + dic[customers.length - 1] - dic[i + X - 1]
            value += totalDic[i + X - 1] - totalDic[i - 1]
        } else if (i == 0) {
            value = dic[customers.length - 1] - dic[X - 1]
            value += totalDic[X - 1]
        } else {
            value = dic[i - 1]
            value += totalDic[i + X - 1] - totalDic[i - 1]
        }
        res = Math.max(value, res)
    }
    return res
};
const assert = require('assert');
// data = maxSatisfied([1, 0, 1, 2, 1, 1, 7, 5], [0, 1, 0, 1, 0, 1, 0, 1], 3)
// assert.strictEqual(data, 16)

// data = maxSatisfied([10, 1, 7], [0, 0, 0], 2)
// assert.strictEqual(data, 18)

data = maxSatisfied([7, 3, 2, 5, 1, 6], [0, 1, 1, 1, 0, 0], 1)
// assert.strictEqual(data, 19)
console.log(data)